package com.thread.pool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestMainCallable {

	public static void main(String[] args) {

		ExecutorService exec = Executors.newCachedThreadPool();
		
		List<Future<String>> list = new ArrayList<>();
		
		for (int i = 0; i < 10; i++) {
			Future<String> future = exec.submit(new PrintCallable(i));
			list.add(future);
		}
		
		exec.shutdown();
		
		
		for (Future<String> future : list) {
			try{
				System.out.println(future.get());
			} catch (Exception e) {
				exec.shutdownNow();
				e.printStackTrace();
			}
		}
		
	}

}
